import { createRouter, createWebHashHistory } from 'vue-router';

/************************************************************************动态添加路由 */
// 找到 components 文件夹下以 index.vue 命名的文件
const requireRouter = require.context("./components", true, /^\.\/(\w*\/)+index\.(vue|js)$/);
let routes = [{
    path: '/',
    name: 'default',
    component: () =>
        import ('@/components/demo01/index')
}];
requireRouter.keys().forEach(fileName => {
    const routerName = fileName.split('/')[1];
    routes.push({
        isDemo: true,
        path: '/' + routerName,
        name: routerName,
        component: requireRouter(fileName).default,
    })
});
/************************************************************************动态添加路由 */


// app router
const router = createRouter({
    history: createWebHashHistory(),
    routes: routes,
    strict: true,
});

export default router